package com.ruoyi.subject.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.subject.domain.Accounting;
import com.ruoyi.subject.service.IAccountingService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;

/**
 * 科目表Controller
 * 
 * @author ruoyi
 * @date 2025-03-03
 */
@RestController
@RequestMapping("/accounting")
public class AccountingController extends BaseController
{
    @Autowired
    private IAccountingService accountingService;

    /**
     * 查询科目表列表
     */
    @RequiresPermissions("subject:accounting:list")
    @GetMapping("/list")
    public AjaxResult list(Accounting accounting)
    {
        List<Accounting> list = accountingService.selectAccountingList(accounting);
        return success(list);
    }

    /**
     * 导出科目表列表
     */
    @RequiresPermissions("subject:accounting:export")
    @Log(title = "科目表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Accounting accounting)
    {
        List<Accounting> list = accountingService.selectAccountingList(accounting);
        ExcelUtil<Accounting> util = new ExcelUtil<Accounting>(Accounting.class);
        util.exportExcel(response, list, "科目表数据");
    }

    /**
     * 获取科目表详细信息
     */
    @RequiresPermissions("subject:accounting:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(accountingService.selectAccountingById(id));
    }

    /**
     * 新增科目表
     */
    @RequiresPermissions("subject:accounting:add")
    @Log(title = "科目表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Accounting accounting)
    {
        return toAjax(accountingService.insertAccounting(accounting));
    }

    /**
     * 修改科目表
     */
    @RequiresPermissions("subject:accounting:edit")
    @Log(title = "科目表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Accounting accounting)
    {
        return toAjax(accountingService.updateAccounting(accounting));
    }

    /**
     * 删除科目表
     */
    @RequiresPermissions("subject:accounting:remove")
    @Log(title = "科目表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(accountingService.deleteAccountingByIds(ids));
    }
}
